﻿namespace HuaWei.CommClass
{
    using System;
    using System.Management;

    public static class SysUtils
    {
        public static string GetComputerName()
        {
            try
            {
                return Environment.GetEnvironmentVariable("ComputerName");
            }
            catch
            {
                return "unknow";
            }
        }

        public static string GetComputerSerialNumber()
        {
            return GetCpuID();
        }

        public static string GetCpuID()
        {
            try
            {
                string str = "";
                ManagementClass class2 = new ManagementClass("Win32_Processor");
                foreach (ManagementObject obj2 in class2.GetInstances())
                {
                    str = obj2.Properties["ProcessorId"].Value.ToString();
                }
                class2 = null;
                return str;
            }
            catch
            {
                return "unknow";
            }
        }

        public static string GetDiskID()
        {
            try
            {
                string str = "";
                ManagementClass class2 = new ManagementClass("Win32_DiskDrive");
                foreach (ManagementObject obj2 in class2.GetInstances())
                {
                    str = (string) obj2.Properties["Model"].Value;
                }
                class2 = null;
                return str;
            }
            catch
            {
                return "unknow";
            }
        }

        public static string GetIPAddress()
        {
            try
            {
                ManagementObjectCollection objects;
                string str = "";
                ManagementClass class2 = new ManagementClass("Win32_NetworkAdapterConfiguration");
                using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = class2.GetInstances().GetEnumerator())
                {
                    ManagementObject current;
                    Array array;
                    while (enumerator.MoveNext())
                    {
                        current = (ManagementObject) enumerator.Current;
                        if ((bool) current["IPEnabled"])
                        {
                            goto Label_0050;
                        }
                    }
                    goto Label_008A;
                Label_0050:
                    array = (Array) current.Properties["IpAddress"].Value;
                    str = array.GetValue(0).ToString();
                }
            Label_008A:
                objects = null;
                class2 = null;
                return str;
            }
            catch
            {
                return "unknow";
            }
        }

        public static string GetMacAddress()
        {
            try
            {
                ManagementObjectCollection objects;
                string str = "";
                ManagementClass class2 = new ManagementClass("Win32_NetworkAdapterConfiguration");
                using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = class2.GetInstances().GetEnumerator())
                {
                    ManagementObject current;
                    while (enumerator.MoveNext())
                    {
                        current = (ManagementObject) enumerator.Current;
                        if ((bool) current["IPEnabled"])
                        {
                            goto Label_0050;
                        }
                    }
                    goto Label_0071;
                Label_0050:
                    str = current["MacAddress"].ToString();
                }
            Label_0071:
                objects = null;
                class2 = null;
                return str;
            }
            catch
            {
                return "unknow";
            }
        }

        public static string GetSystemType()
        {
            try
            {
                string str = "";
                ManagementClass class2 = new ManagementClass("Win32_ComputerSystem");
                foreach (ManagementObject obj2 in class2.GetInstances())
                {
                    str = obj2["SystemType"].ToString();
                }
                class2 = null;
                return str;
            }
            catch
            {
                return "unknow";
            }
        }

        public static string GetTotalPhysicalMemory()
        {
            try
            {
                string str = "";
                ManagementClass class2 = new ManagementClass("Win32_ComputerSystem");
                foreach (ManagementObject obj2 in class2.GetInstances())
                {
                    str = obj2["TotalPhysicalMemory"].ToString();
                }
                class2 = null;
                return str;
            }
            catch
            {
                return "unknow";
            }
        }

        public static string GetUserName()
        {
            try
            {
                string str = "";
                ManagementClass class2 = new ManagementClass("Win32_ComputerSystem");
                foreach (ManagementObject obj2 in class2.GetInstances())
                {
                    str = obj2["UserName"].ToString();
                }
                class2 = null;
                return str;
            }
            catch
            {
                return "unknow";
            }
        }
    }
}

